package com.jp.vn.main;

import android.os.Bundle;
import android.view.View;
import android.support.v4.app.*;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class ThoiGianActivity extends FragmentActivity {
	
	FragmentManager manager;
	ImageView btnMenu;
	ImageView btnDemGio, btnDemPhut, btnThoiGian;
	LinearLayout menu_popup;
	int height = 0;
	int width = 0;
	int space = 0;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_thoi_gian);
		btnMenu = (ImageView) findViewById(R.id.btnMenu);
		btnDemGio = (ImageView) findViewById(R.id.btnDemGio);
		btnDemPhut = (ImageView) findViewById(R.id.btnDemPhut);
		btnThoiGian = (ImageView) findViewById(R.id.btnThoiGian);
		menu_popup = (LinearLayout)findViewById(R.id.menu_popup);
		
		manager = getSupportFragmentManager();
		
        FragmentTransaction transaction= manager.beginTransaction();
        transaction.replace(R.id.fragment_thoigian, new FragmentDemGio(), "myFragment");
        transaction.addToBackStack(null);
        transaction.commit();
		
		btnDemGio.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				FragmentTransaction transaction = manager.beginTransaction();
				transaction.replace(R.id.fragment_thoigian, new FragmentDemGio());
				transaction.commit();
			}
		});
		
		btnDemPhut.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				FragmentTransaction transaction = manager.beginTransaction();
				transaction.replace(R.id.fragment_thoigian, new FragmentDemPhut());
				transaction.commit();
			}
		});
		
		btnThoiGian.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				FragmentTransaction transaction = manager.beginTransaction();
				transaction.replace(R.id.fragment_thoigian, new FragmentThoiGian());
				transaction.commit();
			}
		});
		
		
		btnMenu.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				PopupMenu menu = new PopupMenu(v, height,width);
				menu.showPopup(space+5);
			}
		});
		
	}
	
	@Override
	public void onWindowFocusChanged(boolean hasFocus) {
		super.onWindowFocusChanged(hasFocus);
		width = menu_popup.getWidth();
		menu_popup.setVisibility(View.GONE);
		height = (int) getResources().getDimension(R.dimen.menupopup_height);
		space = (int) getResources().getDimension(R.dimen.menu_height);
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		finish();
	}
	
	@Override
	public void onBackPressed() {
		super.onBackPressed();
		overridePendingTransition(R.anim.left_in, R.anim.right_out);
		finish();
	}
}
